feat(build): add support for marking env vars as secrets in syncEnvVars#2417
feat(build): add support for marking env vars as secrets in syncEnvVars#2417julienvanbeveren wants to merge 5 commits intotriggerdotdev:mainfrom
Conversation
- Added isSecret flag to SyncEnvVarsBody type - Updated CLI's syncEnvVarsWithServer to pass secret flags - Modified backend API endpoint to handle secret flags - Added documentation for the new feature
🦋 Changeset detectedLatest commit: 1edd66e The changes in this PR will be included in the next version bump. This PR includes changesets to release 29 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughAdds per-variable secret support across sync/import flows. New changeset added. API schema and client types gain optional Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Late to the game, but would love to see this as well. Curious if the original work is still good enough or if this needs a new attempt with so much changing in the last year-or-so |
There was a problem hiding this comment.
🔴 Secrets data dropped in syncEnvVars: never stored in build manifest
The callSyncEnvVarsFn function correctly computes secrets and parentSecrets from user callbacks (lines 148-224), but the syncEnvVars function silently drops them when calling context.addLayer() at lines 117-124 — only env and parentEnv are passed in the deploy object. Additionally, the BuildLayer interface (packages/core/src/v3/build/extensions.ts:63-66) and the build manifest schema (packages/core/src/v3/schemas/build.ts:52-57) don't define secrets/parentSecrets fields, so there's no way to carry this data through the manifest pipeline. As a result, the entire "secret flag on variables" feature advertised by this PR is non-functional — isSecret will always resolve to false on the server side (body.secrets?.[key] ?? false).
(Refers to lines 117-124)
Prompt for agents
The secrets data computed in callSyncEnvVarsFn is dropped at line 117 because context.addLayer() only receives env and parentEnv. To fix this:
1. Add secrets and parentSecrets fields to BuildLayer.deploy in packages/core/src/v3/build/extensions.ts (the BuildLayer interface around line 63).
2. Add secrets and parentSecrets fields to the deploy.sync schema in packages/core/src/v3/schemas/build.ts (around line 52-57).
3. In packages/build/src/extensions/core/syncEnvVars.ts, pass result.secrets and result.parentSecrets through context.addLayer() in the deploy object.
4. In packages/cli-v3/src/build/extensions.ts, handle the new secrets/parentSecrets fields when processing layers (around lines 147-186) and store them in the manifest.
5. In packages/cli-v3/src/commands/deploy.ts, read the secrets from buildManifest.deploy.sync and pass them to syncEnvVarsWithServer (see BUG-0002).
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
🔴 syncEnvVarsWithServer called without secrets/parentSecrets arguments in deploy.ts
The syncEnvVarsWithServer function signature was updated to accept secrets and parentSecrets parameters (lines 768-769), but the call site at lines 472-478 only passes childVars and parentVars, omitting the new parameters. Even once the build manifest carries secrets data (see the related manifest schema issue), this call site still needs to be updated to pass them. The same issue exists in the other call site at packages/cli-v3/src/commands/workers/build.ts:272-278 where the function signature wasn't even updated.
(Refers to lines 472-478)
Prompt for agents
The call to syncEnvVarsWithServer at line 472 needs to also pass the secrets and parentSecrets from the build manifest. Once the manifest schema is updated to carry secrets data (see the related BuildLayer/manifest issue), read secrets and parentSecrets from buildManifest.deploy.sync and pass them as the 6th and 7th arguments.
Also update the duplicate call site in packages/cli-v3/src/commands/workers/build.ts around line 272 and its local syncEnvVarsWithServer function at line 448 to accept and forward secrets/parentSecrets as well.
Was this helpful? React with 👍 or 👎 to provide feedback.
|
The per-variable The problemThe route attaches variables: Object.entries(body.variables).map(([key, value]) => ({
key,
value,
isSecret: body.secrets?.[key] ?? false,
})),But Net effect for an existing variable that was previously a secret:
So passing Suggested fixMove
Why per-item rather than two calls bucketed by
|
✅ Checklist
Testing
@trigger.dev/core,@trigger.dev/build,trigger.devCLI)pnpm run typecheck --filter webapp— passes cleanlyChangelog
Added support for the
isSecretflag on per-variable items in thesyncEnvVarsbuild extension, wiring it end-to-end from user callbacks through the build manifest, CLI deploy, API import route, and into theEnvironmentVariablesRepositorystorage layer.Bug fixes (from Devin Review and maintainer feedback):
Secrets data no longer dropped in build manifest pipeline — Added
secretsandparentSecretsfields toBuildLayer.deployinterface, the build manifestdeploy.syncschema, andapplyLayerToManifest. ThesyncEnvVarsextension now passesresult.secretsandresult.parentSecretsthroughcontext.addLayer().Deploy call sites now forward secrets — Updated
syncEnvVarsWithServercall sites in bothdeploy.tsandworkers/build.tsto readsecrets/parentSecretsfrom the build manifest and pass them to the API client.Per-variable
isSecretnow reaches storage — Extended theCreateEnvironmentVariablesschema to support an optionalisSecreton each variable item. UpdatedEnvironmentVariablesRepository.create()to use per-itemisSecret(falling back to the top-leveloptions.isSecret) for inheritance lookup, skip-check, update writes, and insert writes. MaderemoveBlacklistedVariablesgeneric so theisSecrettype is preserved through filtering.Screenshots
N/A — backend-only changes, no UI impact.
💯
Link to Devin session: https://app.devin.ai/sessions/97ecc669a2624b7c82127d1678670773
Requested by: @matt-aitken